import { modal } from 'vue-strap'
import { addBuyType, showMsg } from '../../../../../vuex/action.js'

export default {
  data() {
    return {
      showAddBuyTypeModal: false,
      golds: [1, 2],
      params: {
        type: '',
        price: '',
        remark: ''
      }
    }
  },
  methods: {
    addPay() {
      this.golds.push(1)
    },
    trim(inStr) {
      return inStr.replace(/(^ +)|( +$)/g, '')
    },
    checkValid() {
      if (this.params.type.length === 0) {
        return '请输入收费类型'
      } else if (this.params.price.length === 0) {
        return '请输入金额'
      }
    },
    evtAddBuyType() {
      let validMsg = this.checkValid()
      if (validMsg) {
        return this.xShowMsg({
          type: 'danger',
          content: validMsg
        })
      }

      this.xAddBuyType(this.params).then((res) => {
        this.showAddMoneyTypeModal = false
      })
    }
  },
  components: {
    modal: modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xAddBuyType: addBuyType
    }
  }
}
